package com.wiloon.java.network.network.nettyhttpserver.nettyhttpclient;


import com.wiloon.java.network.network.nettyhttpserver.monitor.RequestMonitor;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by Roy on 2015/12/16;
 * thread pool
 * connection closed by client
 */
public class HttpPressTestOneChannel {
    private static Logger logger = LoggerFactory.getLogger(HttpClient.class);
    private static String host = "192.168";
    private static int port = 7000;
    private static String url;

    public static void main(String[] args) {


        host = "127.0.0.1";
        port = 7777;
        host = "";
        port = 7000;

        url = "http://" + host + ":" + port + "/?msg=";

        host = "127.0.0.1";
        port = 8080;
        url = "http://" + host + ":" + port + "/examples/servlets/servlet/HelloWorldExample";

        try {
            new Thread(new RequestMonitor()).start();
            EventLoopGroup workerGroup = new NioEventLoopGroup();
            HttpClient httpClient = new HttpClient(workerGroup);
            httpClient.connect(host, port, url);
            int i = 1;
            int sleepAfter = 10000;
            while (true) {
                httpClient.sendRequest();
                // logger.info("send");
                if (i++ == sleepAfter) {
                    i = 1;
                    Thread.sleep(1000);
                }


            }
            // httpClient.sync();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
